<template>
	<view class="fui-wrap">
		<view class="logo">
			<image :src="qrcode" mode="widthFix"></image>
			<view v-if="hideqrcode" class="hideqrcode">二维码已过期</view>
			<fui-text text="请使用微信扫码" type="black" size="42" block align="center" fontWeight="800"></fui-text>
		</view>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {getUniqid} from '@/utils/util.js';
	let timer=0;
	export default {
		data() {
			return {
				foreign_key:'',
				qrcode:'',
				init:true,
				hideqrcode:false
			}
		},
		onLoad() {
			this.foreign_key=getUniqid();
			this.$get('merchant/index/qrcode-login',{foreign_key:this.foreign_key}).then(res=>{
				this.qrcode=res;
				this.checkLogin();
			});
		},
		onHide() {
			this.init=false;
		},
		onUnload() {
			this.init=false;
		},
		methods: {
			...methods,
			checkLogin:function(){
				if(timer>=60){
					this.hideqrcode=true;
					return;
				}
				this.$get('merchant/index/check-login',{foreign_key:this.foreign_key}).then(res=>{
					uni.setStorageSync('token',res.token);
					this.$redirectTo('merchant/index');
				}).catch(e=>{
					timer++;
					setTimeout(()=>{
						 this.init && this.checkLogin();
					},2000);
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.logo{
	margin-top: 400rpx;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	image{
		width: 400rpx;
		height: 400rpx;
		margin-bottom: 30rpx;
	}
}
.hideqrcode{
	position: absolute;
	width: 400rpx;
	height: 400rpx;
	background: rgba(280,280,280,0.98);
	top:400rpx;
	text-align: center;
	line-height: 400rpx;
	color: #a1a1a1;
}
</style>